
/*code demos*/

**keep african americans

gen black=0
recode black(0=1) if Q1==2
drop if black==0

**age

gen age=Q5
recode age(1=18)(2=19)(3=20)(4=21)(5=22)(6=23)(7=24)(8=25)(9=26)(10=27)(11=28)(12=29)(13=30)(14=31)(15=32)(16=33)(17=34)(18=35)(19=36)(20=37)(21=38)(22=39)(23=40)(24=41)(25=42)(26=43)(27=44)(28=45)(29=46)(30=47)(31=48)(32=49)(33=50)(34=51)(35=52)(36=53)(37=54)(38=55)(39=56)(40=57)(41=58)(42=59)(43=60)(44=61)(45=62)(46=63)(47=64)(48=65)(49=66)(50=67)(51=68)(52=69)(53=70)(54=71)(55=72)(56=73)(57=74)(58=75)(59=76)(60=77)(61=78)
summ age
summ age, detail

**gender

gen female=0
recode female(0=1) if Q6==1 
tab female

**ideology

gen liberal1=Q8
summ liberal1
gen liberal=(liberal1-1)/6
summ liberal


/*experiment*/

**treatments

encode m1, gen(treats)

gen inferior=0
recode inferior(0=1) if treats==2

gen american=0
recode american(0=1) if treats==3

tab inferior american
tab inferior
tab american


/*SI.2. randomization check*/

reg inferior age female liberal if american==0
test age female liberal


/*SI.2 balance check*/

ttest age if american==0, by(inferior)
ttest female if american==0, by (inferior)  
ttest liberal1 if american==0, by (inferior)


***************************************************************
******to analyze with failed manipulation checks included******
******do not run next nine lines of code**********************
***************************************************************

gen check=0

**control manipulation check

recode check(0=1) if Q14==2

**inferior manipulation check

recode check(0=1) if Q15==2

**american manipulation check

recode check(0=1) if Q16==2


/*characteristics of failed manipulation checks*/

tab check if american==0

ttest age if american==0, by(check)
ttest female if american==0, by(check)
ttest liberal if american==0, by(check)

drop if check==1


/*Total N - dropped N = analyzed sample...restricted to inferiority treatment*/

tab american


/*reassess balance after dropped manipulation check*/

ttest age if american==0, by(inferior)
ttest female if american==0, by (inferior)  
ttest liberal if american==0, by (inferior)

reg inferior age female liberal if american==0
test age female liberal


/*mediator - solidarity with poc*/

gen poc1=Q17
summ poc1

gen poc2=Q18
recode poc2(1=5)(2=4)(3=3)(4=2)(5=1)
summ poc2

alpha poc1 poc2
pwcorr poc1 poc2

gen pocsolid1=(poc1+poc2)/2
summ pocsolid1

gen pocsolid=(pocsolid1-1)/4
summ pocsolid


/*outcomes*/

gen borderpat1=Q19
recode borderpat1(1=5)(2=4)(3=3)(4=2)(5=1)
summ borderpat1

gen daca1=Q20
summ daca1

gen pathway1=Q21
summ pathway1

alpha borderpat1 daca1 pathway1, std

gen hatecrime1=Q22
summ hatecrime1

gen blm1=Q23
recode blm1(1=5)(2=4)(3=3)(4=2)(5=1)
summ blm1

gen repar1=Q23
summ repar1

pwcorr hatecrime1 blm1 repar1, sig

alpha hatecrime1 blm1, std


/*recode variables to 0-1 range*/

gen hatecrime=(hatecrime1-1)/4
gen blm=(blm1-1)/4
gen repar=(repar1-1)/4

gen borderpat=(borderpat1-1)/4
gen daca=(daca1-1)/4
gen pathway=(pathway1-1)/4

summ hatecrime blm repar borderpat daca pathway

**create policy scales for each domain

gen prolat=(borderpat+daca+pathway)/3
summ prolat

gen problk=(blm+hatecrime)/2
summ problk


/*mediation analyses*/

**basic (baron and kenny)

reg pocsolid inferior if american==0
ttest pocsolid if american==0, by(inferior)

reg hatecrime pocsolid if american==0
reg blm pocsolid if american==0
reg repar pocsolid if american==0
reg problk pocsolid if american==0

reg problk inferior if american==0

reg borderpat pocsolid if american==0
reg daca pocsolid if american==0
reg pathway pocsolid if american==0
reg prolat pocsolid if american==0

reg prolat pocsolid if american==0

reg prolat inferior american
reg problk inferior american


**robust to ideology

reg hatecrime pocsolid liberal if american==0
reg blm pocsolid liberal if american==0
reg problk pocsolid liberal if american==0

reg borderpat pocsolid liberal if american==0
reg daca pocsolid liberal if american==0
reg pathway pocsolid liberal if american==0
reg prolat pocsolid liberal if american==0


/*results for SI.5*/

reg pocsolid inferior american
reg prolat inferior american


/*generate comparison of inferiority treatment to conrol only*/

gen inferior2=.
recode inferior2(.=1) if inferior==1
recode inferior2(.=0) if treats==1
tab inferior2

ttest pocsolid, by(inferior2)
ttest prolat, by(inferior2)

**table 2's results, with ideology as a covariate in the downstream path

medeff (regress pocsolid inferior2) (regress prolat inferior2 pocsolid liberal), mediate(pocsolid) treat(inferior2) sims(1000) seed(1) level(92)
medeff (regress pocsolid inferior2) (regress borderpat inferior2 pocsolid liberal), mediate(pocsolid) treat(inferior2) sims(1000) seed(1)
medeff (regress pocsolid inferior2) (regress pathway inferior2 pocsolid liberal), mediate(pocsolid) treat(inferior2) sims(1000) seed(1)
medeff (regress pocsolid inferior2) (regress daca inferior2 pocsolid liberal), mediate(pocsolid) treat(inferior2) sims(1000) seed(1)

medeff (regress pocsolid inferior2) (regress problk inferior2 pocsolid liberal), mediate(pocsolid) treat(inferior2) sims(1000) seed(1)
medeff (regress pocsolid inferior2) (regress hatecrime inferior2 pocsolid liberal), mediate(pocsolid) treat(inferior2) sims(1000) seed(1)
medeff (regress pocsolid inferior2) (regress blm inferior2 pocsolid liberal), mediate(pocsolid) treat(inferior2) sims(1000) seed(1)

pwcorr pocsolid liberal age female, sig


**sensitivity analyses

medsens (regress pocsolid inferior2) (regress prolat inferior2 pocsolid liberal), mediate(pocsolid) treat(inferior2) sims(1000) 


/*does gender moderate treatment effect on solidarity?*/

gen infem=(inferior*female)

reg pocsolid inferior female
reg pocsolid inferior female infem if american==0
test female infem

**results for SI.6

medeff (regress pocsolid inferior2) (regress borderpat inferior2 pocsolid), mediate(pocsolid) treat(inferior2) sims(1000) seed(1)
medeff (regress pocsolid inferior2) (regress pathway inferior2 pocsolid), mediate(pocsolid) treat(inferior2) sims(1000) seed(1)
medeff (regress pocsolid inferior2) (regress daca inferior2 pocsolid), mediate(pocsolid) treat(inferior2) sims(1000) seed(1)
medeff (regress pocsolid inferior2) (regress prolat inferior2 pocsolid), mediate(pocsolid) treat(inferior2) sims(1000) seed(1)

medeff (regress pocsolid inferior2) (regress hatecrime inferior2 pocsolid), mediate(pocsolid) treat(inferior2) sims(1000) seed(1)
medeff (regress pocsolid inferior2) (regress blm inferior2 pocsolid), mediate(pocsolid) treat(inferior2) sims(1000) seed(1)
medeff (regress pocsolid inferior2) (regress problk inferior2 pocsolid), mediate(pocsolid) treat(inferior2) sims(1000) seed(1)

/*results for SI.7*/

**with only first solidarity item as mediator

gen poc11=(poc1-1)/4
summ poc11


medeff (regress poc11 inferior2) (regress prolat inferior2 poc11 liberal), mediate(poc11) treat(inferior2) sims(1000) seed(1) level(90)
medeff (regress poc11 inferior2) (regress problk inferior2 poc11 liberal), mediate(poc11) treat(inferior2) sims(1000) seed(1) level(90)

**with only second solidarity item as mediator

gen poc22=(poc2-1)/4
summ poc22

medeff (regress poc22 inferior2) (regress prolat inferior2 poc22 liberal), mediate(poc22) treat(inferior2) sims(1000) seed(1) level(80)
medeff (regress poc22 inferior2) (regress problk inferior2 poc22 liberal), mediate(poc22) treat(inferior2) sims(1000) seed(1) level(90)


**treatment effects on solidarity with gender as covariate

reg pocsolid inferior2 
reg pocsolid inferior2 female


**robust to ideology, single solidarity items

reg hatecrime poc11 liberal
reg hatecrime poc22 liberal

reg blm poc11 liberal
reg blm poc22 liberal

reg borderpat poc11 liberal
reg borderpat poc22 liberal

reg daca poc11 liberal
reg daca poc22 liberal

reg pathway poc11 liberal
reg pathway poc22 liberal


